/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.actions;

import EDT.api.API;
import EDT.form.EmpEcForm;
import EDT.obj.Calendrier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author ali
 */
public class EmpEcAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
         EmpEcForm f = (EmpEcForm) form;
        
        int annee = EDT.api.API.getAnnee(f.getPromotion());
        
        Calendrier c = EDT.api.API.getCalendrierEc(f.getEc(),f.getPromotion());
        c.setTitre("Emplois du temps " +" "+f.getFormation()+"<br/>Promotion : "+annee+"/"+(annee+1));
        
        
        
        /*
         Date d = new Date();
            Calendar cal = Calendar.getInstance(); 
            cal.setTime(d);
        
            cal.add(Calendar.DATE, -4);
           
            //cal.add(Calendar.DATE, 1);
        
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 800, 1100,"CM"));
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 1100, 1200,"TD"));
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 1700, 1800,"TD"));
            * 
            */
           
        request.setAttribute("calendrier", c.perideToTableHTML());
         
        return mapping.findForward("calendrier");
    }
}
